package com.songlanyun.modules.information.model.vo;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.songlanyun.common.drive.Increment;
import com.songlanyun.modules.goods.model.vo.GoodsSlimVo;
import com.songlanyun.modules.goods.service.GoodsService;
import com.songlanyun.modules.rabbitmq.util.SpringContextUtil;
import com.songlanyun.modules.shop.entity.ShopEntity;
import com.songlanyun.modules.shop.service.ShopService;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;
import java.util.List;

/**
 * 资讯
 *
 * @author WuChao
 * @email songlanyun@gmail.com
 * @date 2022-11-18 09:52:58
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class InformationVo extends Increment {

    /**
     *
     */
    private Long id;
    /**
     * 标题
     */
    private String title;
    /**
     * 分类ID
     */
    private Long classifyId;
    /**
     * 分类名称
     */
    private String classifyName;
    /**
     * 缩略图
     */
    private JSONArray thumbnail;
    /**
     * 内容
     */
    private String content;
    /**
     * 序号
     */
    private Integer sort;
    /**
     * 发布者
     */
    private String publisher;
    /**
     * 推荐商品
     */
    private JSONArray recommendGoods;
    private List<GoodsSlimVo> recommendGoodsList;

    public void loadRecommendGoods() {
        if (ObjectUtil.isNotNull(recommendGoods) && recommendGoods.size() > 0) {
            GoodsService goodsService = (GoodsService) SpringContextUtil.getBean("goodsService");
            List<Long> goodsIds = recommendGoods.toJavaList(Long.class);
            this.recommendGoodsList = goodsService.queryRecommend(goodsIds);
        }
    }

    /**
     * 推荐门店
     */
    private JSONArray recommendShops;
    private List<ShopEntity> recommendShopList;

    public void loadRecommendShops(Boolean isShow) {
        if (ObjectUtil.isNotNull(recommendShops) && recommendShops.size() > 0) {
            ShopService shopService = (ShopService) SpringContextUtil.getBean("yxtShopService");
            this.recommendShopList = shopService.lambdaQuery()
                    .eq(ObjectUtil.isNotNull(isShow), ShopEntity::getIsShow, isShow)
                    .in(ShopEntity::getId, recommendShops)
                    .orderByDesc(ShopEntity::getCreateTime)
                    .list();
        }
    }

    /**
     * 置顶
     */
    private Boolean top;
    /**
     * 置顶结束时间
     */
    private Date topEndTime;
    /**
     * 是否置顶
     */
    private Boolean stick;

    public Boolean loadStick() {
        return this.stick = this.top && this.topEndTime.getTime() > System.currentTimeMillis();
    }

    /**
     * 推荐
     */
    private Boolean recommend;

    /**
     * 创建人
     */
    private String creator;

    /**
     *
     */
    private Date createTime;

}
